package com.kmu.yss.dao.imp;

import com.kmu.yss.dao.LoginDao;
import com.kmu.yss.entity.LoginDetail;
import com.kmu.yss.factory.HibernateFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

public class LoginDaoImp implements LoginDao {
    @Override
    public LoginDetail validateUser(String studentNo, String token) {
        Session session = HibernateFactory.getSession();
        Transaction transaction = session.beginTransaction();
        Query query = session.createQuery("from LoginDetail where studentNo = ?1 and token = ?2").setParameter(1, studentNo).setParameter(2, token).setMaxResults(1);
        LoginDetail loginDetail = (LoginDetail) query.uniqueResult();
        transaction.commit();
        session.close();
        return loginDetail;
    }
}
